var global = {
    apiUrl:'https://mdn.tfnhg.com',
    titleText:'PAPN 减重管理后台'
}
//设置统一title
$('title').text(global.titleText);

//ajax封装
function  getAjax(url,callback,data) {
    $.ajax({
        url:url,
        type:'get',
        data:data,
        dataType:'json',
        success(res){
            callback(res)
        }
    })
}
function  getAjaxAsync(url,callback,data) {
    $.ajax({
        url:url,
        type:'get',
        data:data,
        async:false,
        dataType:'json',
        success(res){
            callback(res)
        }
    })
}
function getSearch(){
    var search = window.location.search;
    search = search.slice(1);
    var searchArr = search.split("&");
    var searchObj = {};
    for(var i=0;i<searchArr.length;i++){
        var key = searchArr[i].split('=')[0];
        var val = searchArr[i].split('=')[1];
        eval("searchObj."+key +"="+ val);
    }
    return searchObj
}

//时间戳转换为日期
function timeStampToTime(timeStamp){
    var date = new Date(timeStamp*1000);
    var Y = date.getFullYear();
    var M = (date.getMonth()+1)<10?'0'+(date.getMonth()+1):date.getMonth()+1;
    var D = date.getDate()<10?'0'+date.getDate():date.getDate();
    var h = date.getHours()<10?'0'+date.getHours():date.getHours();
    var m = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes();
    var s = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds();
    return `${Y}年${M}月${D}日 ${h}:${m}:${s}`
};
//获取订单状态
//status 4未支付  1已支付未发货 2已支付已收货   3已支付已发货
function orderStatus(status){
    if(status == 1){
        return '未发货'
    }else if(status==2){
        return '已完成'
    }else if(status == 3){
        return '待收货'
    }
}
function orderStatusStyle(status){
    if(status == 1){
        return 'btn-warning'
    }else if(status==2){
        return 'btn-primary'
    }else if(status == 3){
        return 'btn-success'
    }
}
$('#order-list').on('click','.orderDetails',function(){
    var orderId = $(this).data('id');
    console.log(orderId);
    // window.location.href='order-details.html?id='+orderId
    window.open('order-details.html?id='+orderId);
})

//接收参数
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

//判断是否登陆
var isLogin = sessionStorage.getItem('status');
console.log(isLogin);
if(isLogin == 1){

}else{
    location.href = 'login.html'
}
